package web.servlet;

import domain.Account;
import domain.Cart;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class CartFormServlet extends HttpServlet {

    private static final String CART_FORM = "/WEB-INF/jsp/cart/cart.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Cart cart = (Cart) session.getAttribute("cart");
        Account loginAccount = (Account) session.getAttribute("loginAccount");
        if(cart == null){
            cart = new Cart();
        }
        session.setAttribute("cart",cart);
        session.setAttribute("loginAccount",loginAccount);
        req.getRequestDispatcher(CART_FORM).forward(req,resp);
    }
}
